<template>
    <view>
        <view>
            {{ globalText }}
        </view>
        <view>
            <button type="primary" @tap="bindtap">点击</button>
        </view>
    </view>
</template>

<script>
// pages/common/v-model/v-model.js
export default {
    data() {
        return {
            globalText: getApp().globalData.globalText
        };
    },

    /**
     * 组件的属性列表
     */
    props: {},

    watch: {
        globalText: {
            handler: function (res) {
                // console.log('=======================v-model:observers:',res,getApp().globalData.globalText);
                getApp().globalData.globalText = res; // console.log('=======================v-model:observers:',res,getApp().globalData.globalText);
            },

            immediate: true,
            deep: true
        }
    },

    beforeMount: function () {
        // 在组件实例进入页面节点树时执行
        console.log('======================= v-model:lifetimes:attached:');
    },

    destroyed: function () {
        // 在组件实例被从页面节点树移除时执行
        console.log('--- v-model:lifetimes:detached:');
    },

    onPageShow: function () {
        // 页面被展示
        console.log('======================= v-model:pageLifetimes:show:', this.globalText, getApp().globalData.globalText);
        this.globalText = getApp().globalData.globalText
    },

    onPageHide: function () {
        // 页面被隐藏
        console.log('--- v-model:pageLifetimes:hide:');
    },

    onPageResize: function () {
        // 页面尺寸变化
        console.log('=== v-model:pageLifetimes:resize:');
    },

    /**
     * 组件的方法列表
     */
    methods: {
        bindtap() {
            this.globalText = (this.globalText += 1)
        }
    }
};
</script>
<style>
/* pages/common/v-model/v-model.wxss */
</style>
